<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/29
 * Time: 10:46
 */
namespace App\Http\Controllers\Api\V5;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Dingo\Api\Routing\Helpers;
use App\Models\V1\MemberModel;

class BaseController extends Controller
{
    // 接口帮助调用
    use Helpers;
    /**
     * 签名方法
     * @var string
     */
    protected $sign_method = 'md5';
    protected $sign_name = 'laohoulundao';

    /**
     * 校验签名
     * @param  [type] $params [description]
     * @return [type]         [description]
     */
    protected function checkSign($params)
    {
        return true;
    }

    /**
     * 生成签名
     * @param  array $params 待校验签名参数
     * @return string|false
     */
    protected function generateSign($params)
    {
        if ($this->sign_method == 'md5') {
            $t = $this->generateMd5Sign($params);
            return $t;
        }

        return false;
    }

    /**
     * md5方式签名
     * @param  array $params 待签名参数
     * @return string
     */
    protected function generateMd5Sign($params)
    {
        ksort($params);
        $tmps = array();
        foreach ($params as $k => $v) {
            //$tmps[] = $k . $v;
            $tmps[] = $v;
        }
        $string = implode('', $tmps) . $this->sign_name;

        // return strtoupper(md5($string));
        return md5($string);
    }


    /**
     * 获取用户信息
     * */
    protected function member_info($mobile,$key){
        $memberModel    = new MemberModel();
        return $memberModel->get_member_info_by_mobile_key($mobile,$key);
    }

}